<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
    // 登录页
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $user = $_POST['username'] ?? '';
        $pass = $_POST['password'] ?? '';
        // 默认用户名：admin，密码：hyjs2024
        if ($user === 'admin' && $pass === 'hyjs2024') {
            $_SESSION['admin_logged_in'] = true;
            header('Location: index.php');
            exit;
        } else {
            $error = '用户名或密码错误';
        }
    }
    ?>
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>后台登录 - 幻影工具网</title>
        <script src="https://cdn.tailwindcss.com"></script>
    </head>
    <body class="bg-gradient-to-br from-blue-100 to-indigo-100 min-h-screen flex items-center justify-center">
        <form method="post" class="bg-white rounded-2xl shadow-xl p-8 w-80 flex flex-col gap-4">
            <h2 class="text-2xl font-bold text-center text-blue-700 mb-2">后台登录</h2>
            <?php if (!empty($error)): ?><div class="text-red-500 text-center text-sm"><?php echo $error; ?></div><?php endif; ?>
            <input name="username" type="text" placeholder="用户名" class="border rounded px-3 py-2" required autofocus>
            <input name="password" type="password" placeholder="密码" class="border rounded px-3 py-2" required>
            <button class="bg-gradient-to-r from-blue-500 to-indigo-500 text-white rounded-lg py-2 font-bold mt-2" type="submit">登录</button>
        </form>
    </body>
    </html>
    <?php
    exit;
}

// 获取当前页面
$currentPage = $_GET['page'] ?? 'dashboard';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仪表盘 - 幻影工具网</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 min-h-screen">
    <!-- 顶部导航 -->
    <nav class="bg-white shadow-sm border-b border-gray-200 sticky top-0 z-10">
        <div class="max-w-7xl mx-auto px-4 flex justify-between items-center h-16">
            <h1 class="text-xl font-bold text-blue-700">幻影工具网后台</h1>
            <div class="flex items-center space-x-4">
                <a href="/" class="text-gray-600 hover:text-blue-700">返回前台</a>
                <a href="logout.php" class="text-red-600 hover:text-red-800">退出登录</a>
            </div>
        </div>
    </nav>
    <div class="flex min-h-screen">
        <!-- 侧边栏 -->
        <aside class="w-64 bg-white shadow-md hidden md:block">
            <nav class="mt-8 space-y-2 px-4">
                <a href="index.php" class="block px-4 py-2 rounded-lg bg-blue-50 text-blue-700 font-bold">仪表盘</a>
                <a href="plugins.php" class="block px-4 py-2 rounded-lg text-gray-600 hover:bg-blue-50 hover:text-blue-700">插件管理</a>
                <a href="categories.php" class="block px-4 py-2 rounded-lg text-gray-600 hover:bg-blue-50 hover:text-blue-700">分类管理</a>
                <a href="stats.php" class="block px-4 py-2 rounded-lg text-gray-600 hover:bg-blue-50 hover:text-blue-700">数据统计</a>
                <a href="logs.php" class="block px-4 py-2 rounded-lg text-gray-600 hover:bg-blue-50 hover:text-blue-700">操作日志</a>
            </nav>
        </aside>
        <!-- 主内容区 -->
        <main class="flex-1 p-6">
            <div class="mb-8">
                <h2 class="text-2xl font-bold text-gray-900 mb-2">仪表盘</h2>
                <p class="text-gray-500">欢迎使用幻影工具网后台管理系统</p>
            </div>
            <!-- 统计卡片 -->
            <div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
                <div class="bg-white rounded-xl shadow p-6 flex items-center">
                    <div class="p-3 rounded-full bg-blue-100 text-blue-600">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path>
                        </svg>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-gray-600">总插件数</p>
                        <p class="text-2xl font-semibold text-gray-900"><?php echo (int)$pluginCount; ?></p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow p-6 flex items-center">
                    <div class="p-3 rounded-full bg-yellow-100 text-yellow-600">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"></path>
                        </svg>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-gray-600">分类数量</p>
                        <p class="text-2xl font-semibold text-gray-900"><?php echo (int)$categoryCount; ?></p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow p-6 flex items-center">
                    <div class="p-3 rounded-full bg-green-100 text-green-600">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path>
                        </svg>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-gray-600">总浏览量</p>
                        <p class="text-2xl font-semibold text-gray-900"><?php echo (int)$views; ?></p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow p-6 flex items-center">
                    <div class="p-3 rounded-full bg-purple-100 text-purple-600">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"></path>
                        </svg>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-gray-600">总点赞数</p>
                        <p class="text-2xl font-semibold text-gray-900"><?php echo (int)$likes; ?></p>
                    </div>
                </div>
            </div>
            <!-- 快速操作 -->
            <div class="bg-white rounded-xl shadow p-6">
                <h3 class="text-lg font-semibold text-gray-900 mb-4">快速操作</h3>
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                    <a href="plugins.php" class="flex items-center p-4 border border-gray-200 rounded-lg hover:bg-blue-50 transition-colors">
                        <svg class="w-8 h-8 text-blue-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
                        </svg>
                        <div>
                            <p class="font-medium text-gray-900">添加插件</p>
                            <p class="text-sm text-gray-600">上传新的插件</p>
                        </div>
                    </a>
                    <a href="categories.php" class="flex items-center p-4 border border-gray-200 rounded-lg hover:bg-green-50 transition-colors">
                        <svg class="w-8 h-8 text-green-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"></path>
                        </svg>
                        <div>
                            <p class="font-medium text-gray-900">管理分类</p>
                            <p class="text-sm text-gray-600">添加或编辑分类</p>
                        </div>
                    </a>
                    <a href="stats.php" class="flex items-center p-4 border border-gray-200 rounded-lg hover:bg-purple-50 transition-colors">
                        <svg class="w-8 h-8 text-purple-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path>
                        </svg>
                        <div>
                            <p class="font-medium text-gray-900">查看统计</p>
                            <p class="text-sm text-gray-600">数据分析报告</p>
                        </div>
                    </a>
                </div>
            </div>
        </main>
    </div>
</body>
</html> 